<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/29 0029
 * Time: 16:03
 */

namespace app\wap\controller;
use think\Db;
use think\Paginator;


class kephome extends Base
{
    public function index($id=0){
        session('class_id',null);
        //选择
        if($id!=0){
            session('class_id',$id);
            $where=[
                'z.is_del'=>0,
                'z.is_show'=>1,
                'z.sign'=>"mobile",
                'j.show'=>2,
                'j.class_id'=>$id
            ];
            $data_kp = Db::name('works')->alias('z')
                ->join('worksclass j','z.class_id=j.class_id')
                ->where($where)
                ->order('z.sort desc,z.id desc')
                ->field('z.title,z.id,z.main_img,z.click,z.create_time,j.class_id,j.name as jname')
                ->select();
//            $page = $data_kp->render();
//            $this->assign('page', $page);
        }else{
            $where=[
                'z.is_del'=>0,
                'z.is_show'=>1,
                'z.sign'=>"mobile"
            ];
            $data_kp = Db::name('works')->alias('z')
                ->join('worksclass j','z.class_id=j.class_id')
                ->where($where)
                ->order('z.sort desc,z.id desc')
                ->field('z.title,z.id,z.main_img,z.create_time,z.click,j.class_id,j.name as jname')
                ->select();
//            $page = $data_kp->render();
//            $this->assign('page', $page);
        }

        $this->assign('data_kp',$data_kp);

//            $data_style
        //选择分类
        $data_style = Db::name('worksclass')->where('show',2)->select();
        $this->assign('data_style',$data_style);

        //作品
//            $data = Db::name('zp')->where($where)->order('sort desc,id desc')->field('title,id,main_img,ps_time')->limit(8)->select();
//            $data_next= Db::name('zp')->where($where)->order('sort desc,id desc')->field('title,id,main_img,ps_time')->page(2,8)->select();
//            $type = 1;
//            if(!$data_next){
//                $type = 2;
//            }
//            $this->assign('type',$type);
//            $this->assign('data',$data);
        //场馆基地(顶部导航推荐)

        return $this->fetch();
    }

    //客片详情页
    public function details($id=0,$nid=0,$pid=0){
        if(!empty($id)){
//            $where['id']=$id;
            $where = [
                'a.sign'=>"mobile",
                'a.is_del'=>0,
                'a.is_show'=>1,
                'a.id'=>$id
            ];
            $data_kp = Db::name('works')->alias('a')
                ->where($where)
                ->order('a.sort desc,a.id desc')
                ->find();
            $this->assign('data_kp',$data_kp);
        }else{
            return json(['code'=>0,'msg'=>'非法请求']);
        }
        return $this->fetch();
    }

    //客照内容
    public function fg(){
        $id = intval(input('param.id'));
        if($id){
            $data = Db::name('zp')->where('id',$id)->find();
            if($data['works_photo'] !==''){
                $imgurl = Db::name('works_pic')->where('pic_id','in',$data['works_photo'])->select();
                $data['imgurl']=$imgurl;
            }
            $this->assign('data',$data);
            //上一组
            $upId = Db::name('zp')->where('id','<',$id)->where('is_del=0 and is_show=1 and sign="pc"')->order('id desc')->limit(1)->value('id');
            $this->assign('upId',$upId);
            //下一组
            $downId = Db::name('zp')->where('id','>',$id)->where('is_del=0 and is_show=1 and sign="pc"')->order('id asc')->limit(1)->value('id');
            $this->assign('downId',$downId);
        }
        //活动推荐
        $hd = Db::name('activity')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->limit(2)->field('id,main_img')->select();
        $this->assign('hd',$hd);
        //场馆基地(顶部导航推荐)
        $data_cg = Db::name('psjd')->where('is_del=0 and is_show=1 and sign="pc" and is_recom=1')->order('sort desc,id desc')->select();
        $this->assign('data_cg',$data_cg);
        $this->assign('data_seo',getColumnseo(3));
        return $this->fetch();
    }

    public  function  getmore()
    {
        $cg_id = intval(input('post.cg_id'));
        $venue_id = intval(input('post.venue_id'));
        $style_id = intval(input('post.style_id'));
        $where = 'is_del=0 and is_show=1 and sign="pc"';
        $page = intval(input('post.page'));
        //广告
        if($cg_id){
            $where .=' and cg_id = '.$cg_id;
        }
        if($style_id){
            $where .=' and style_id = '.$style_id;
        }
        if($venue_id){
            $where .=' and venue_id = '.$venue_id;
        }

        $data = Db::name('zp')->where($where)->field("id,title,main_img,ps_time")->page($page,8)->select();
        $next_data = Db::name('zp')->where($where)->order('sort desc,id desc')->field('title,id,main_img,ps_time')->page($page+1,8)->select();
        $type = 1;
        if(!$next_data){
            $type = 2;
        }
        if ($data) {
            return json(['code' => 1, 'data' => $data,'type'=>$type]);
        } else {
            return json(['code' => 0, 'msg' => '没有更多了']);
        }
    }


}